/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.portlet.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.portlet.service.ClpSerializer;
import com.portlet.service.nhanvienLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Thi
 */
public class nhanvienClp extends BaseModelImpl<nhanvien> implements nhanvien {
	public nhanvienClp() {
	}

	public Class<?> getModelClass() {
		return nhanvien.class;
	}

	public String getModelClassName() {
		return nhanvien.class.getName();
	}

	public String getPrimaryKey() {
		return _maNhanVien;
	}

	public void setPrimaryKey(String primaryKey) {
		setMaNhanVien(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return _maNhanVien;
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey((String)primaryKeyObj);
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("maNhanVien", getMaNhanVien());
		attributes.put("tenNhanVien", getTenNhanVien());
		attributes.put("gioiTinh", getGioiTinh());
		attributes.put("ngaySinh", getNgaySinh());
		attributes.put("maBoPhan", getMaBoPhan());
		attributes.put("maRole", getMaRole());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		String maNhanVien = (String)attributes.get("maNhanVien");

		if (maNhanVien != null) {
			setMaNhanVien(maNhanVien);
		}

		String tenNhanVien = (String)attributes.get("tenNhanVien");

		if (tenNhanVien != null) {
			setTenNhanVien(tenNhanVien);
		}

		String gioiTinh = (String)attributes.get("gioiTinh");

		if (gioiTinh != null) {
			setGioiTinh(gioiTinh);
		}

		Date ngaySinh = (Date)attributes.get("ngaySinh");

		if (ngaySinh != null) {
			setNgaySinh(ngaySinh);
		}

		String maBoPhan = (String)attributes.get("maBoPhan");

		if (maBoPhan != null) {
			setMaBoPhan(maBoPhan);
		}

		String maRole = (String)attributes.get("maRole");

		if (maRole != null) {
			setMaRole(maRole);
		}
	}

	public String getMaNhanVien() {
		return _maNhanVien;
	}

	public void setMaNhanVien(String maNhanVien) {
		_maNhanVien = maNhanVien;

		if (_nhanvienRemoteModel != null) {
			try {
				Class<?> clazz = _nhanvienRemoteModel.getClass();

				Method method = clazz.getMethod("setMaNhanVien", String.class);

				method.invoke(_nhanvienRemoteModel, maNhanVien);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public String getTenNhanVien() {
		return _tenNhanVien;
	}

	public void setTenNhanVien(String tenNhanVien) {
		_tenNhanVien = tenNhanVien;

		if (_nhanvienRemoteModel != null) {
			try {
				Class<?> clazz = _nhanvienRemoteModel.getClass();

				Method method = clazz.getMethod("setTenNhanVien", String.class);

				method.invoke(_nhanvienRemoteModel, tenNhanVien);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public String getGioiTinh() {
		return _gioiTinh;
	}

	public void setGioiTinh(String gioiTinh) {
		_gioiTinh = gioiTinh;

		if (_nhanvienRemoteModel != null) {
			try {
				Class<?> clazz = _nhanvienRemoteModel.getClass();

				Method method = clazz.getMethod("setGioiTinh", String.class);

				method.invoke(_nhanvienRemoteModel, gioiTinh);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public Date getNgaySinh() {
		return _ngaySinh;
	}

	public void setNgaySinh(Date ngaySinh) {
		_ngaySinh = ngaySinh;

		if (_nhanvienRemoteModel != null) {
			try {
				Class<?> clazz = _nhanvienRemoteModel.getClass();

				Method method = clazz.getMethod("setNgaySinh", Date.class);

				method.invoke(_nhanvienRemoteModel, ngaySinh);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public String getMaBoPhan() {
		return _maBoPhan;
	}

	public void setMaBoPhan(String maBoPhan) {
		_maBoPhan = maBoPhan;

		if (_nhanvienRemoteModel != null) {
			try {
				Class<?> clazz = _nhanvienRemoteModel.getClass();

				Method method = clazz.getMethod("setMaBoPhan", String.class);

				method.invoke(_nhanvienRemoteModel, maBoPhan);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public String getMaRole() {
		return _maRole;
	}

	public void setMaRole(String maRole) {
		_maRole = maRole;

		if (_nhanvienRemoteModel != null) {
			try {
				Class<?> clazz = _nhanvienRemoteModel.getClass();

				Method method = clazz.getMethod("setMaRole", String.class);

				method.invoke(_nhanvienRemoteModel, maRole);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public BaseModel<?> getnhanvienRemoteModel() {
		return _nhanvienRemoteModel;
	}

	public void setnhanvienRemoteModel(BaseModel<?> nhanvienRemoteModel) {
		_nhanvienRemoteModel = nhanvienRemoteModel;
	}

	public Object invokeOnRemoteModel(String methodName,
		Class<?>[] parameterTypes, Object[] parameterValues)
		throws Exception {
		Object[] remoteParameterValues = new Object[parameterValues.length];

		for (int i = 0; i < parameterValues.length; i++) {
			if (parameterValues[i] != null) {
				remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
			}
		}

		Class<?> remoteModelClass = _nhanvienRemoteModel.getClass();

		ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

		Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isPrimitive()) {
				remoteParameterTypes[i] = parameterTypes[i];
			}
			else {
				String parameterTypeName = parameterTypes[i].getName();

				remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
			}
		}

		Method method = remoteModelClass.getMethod(methodName,
				remoteParameterTypes);

		Object returnValue = method.invoke(_nhanvienRemoteModel,
				remoteParameterValues);

		if (returnValue != null) {
			returnValue = ClpSerializer.translateOutput(returnValue);
		}

		return returnValue;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			nhanvienLocalServiceUtil.addnhanvien(this);
		}
		else {
			nhanvienLocalServiceUtil.updatenhanvien(this);
		}
	}

	@Override
	public nhanvien toEscapedModel() {
		return (nhanvien)ProxyUtil.newProxyInstance(nhanvien.class.getClassLoader(),
			new Class[] { nhanvien.class }, new AutoEscapeBeanHandler(this));
	}

	public nhanvien toUnescapedModel() {
		return this;
	}

	@Override
	public Object clone() {
		nhanvienClp clone = new nhanvienClp();

		clone.setMaNhanVien(getMaNhanVien());
		clone.setTenNhanVien(getTenNhanVien());
		clone.setGioiTinh(getGioiTinh());
		clone.setNgaySinh(getNgaySinh());
		clone.setMaBoPhan(getMaBoPhan());
		clone.setMaRole(getMaRole());

		return clone;
	}

	public int compareTo(nhanvien nhanvien) {
		String primaryKey = nhanvien.getPrimaryKey();

		return getPrimaryKey().compareTo(primaryKey);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof nhanvienClp)) {
			return false;
		}

		nhanvienClp nhanvien = (nhanvienClp)obj;

		String primaryKey = nhanvien.getPrimaryKey();

		if (getPrimaryKey().equals(primaryKey)) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return getPrimaryKey().hashCode();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(13);

		sb.append("{maNhanVien=");
		sb.append(getMaNhanVien());
		sb.append(", tenNhanVien=");
		sb.append(getTenNhanVien());
		sb.append(", gioiTinh=");
		sb.append(getGioiTinh());
		sb.append(", ngaySinh=");
		sb.append(getNgaySinh());
		sb.append(", maBoPhan=");
		sb.append(getMaBoPhan());
		sb.append(", maRole=");
		sb.append(getMaRole());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(22);

		sb.append("<model><model-name>");
		sb.append("com.portlet.model.nhanvien");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>maNhanVien</column-name><column-value><![CDATA[");
		sb.append(getMaNhanVien());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>tenNhanVien</column-name><column-value><![CDATA[");
		sb.append(getTenNhanVien());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>gioiTinh</column-name><column-value><![CDATA[");
		sb.append(getGioiTinh());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>ngaySinh</column-name><column-value><![CDATA[");
		sb.append(getNgaySinh());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>maBoPhan</column-name><column-value><![CDATA[");
		sb.append(getMaBoPhan());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>maRole</column-name><column-value><![CDATA[");
		sb.append(getMaRole());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private String _maNhanVien;
	private String _tenNhanVien;
	private String _gioiTinh;
	private Date _ngaySinh;
	private String _maBoPhan;
	private String _maRole;
	private BaseModel<?> _nhanvienRemoteModel;
}